package com.vito.dcs.asphalt.trace.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONObject;
import com.vito.base.factory.IDFactory;
import com.vito.base.model.DataGrid;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.dcs.asphalt.trace.dao.TraceAsphaltMapper;
import com.vito.dcs.asphalt.trace.model.TraceAsphaltModel;
import com.vito.dcs.asphalt.trace.service.TraceAsphaltService;
import com.vito.dcs.intface.dao.IntfaceMapper;
import com.vito.dcs.sys.constructionVehicle.dao.SysConstructionVehicleMapper;

/**
 * TraceAsphaltService接口实现类
 * @author  lyhao E-mail: 
 * @version 0.0.1
 * @date    2019-4-22 17:35:19
 */
@Service
public class TraceAsphaltServiceImpl implements TraceAsphaltService {
	
	@Autowired
	private TraceAsphaltMapper traceasphaltMapper;
	
	@Override
	public void saveTraceAsphalt(TraceAsphaltModel traceasphalt){
		  traceasphalt.setId(IDFactory.getIDFactory().getIdInc()+"");        
		traceasphaltMapper.saveTraceAsphalt(traceasphalt);
	}
	@Override
	public DataGrid<TraceAsphaltModel> queryTraceAsphaltByPage(TraceAsphaltModel traceasphalt){
		DataGrid<TraceAsphaltModel> dg = new DataGrid<TraceAsphaltModel>();
		dg.setRows(traceasphaltMapper.queryTraceAsphaltByPage(traceasphalt));
		dg.setTotal(traceasphalt.getTotal());
		return dg;
	}
	@Override
	public TraceAsphaltModel queryTraceAsphalt(TraceAsphaltModel traceasphalt){
		return traceasphaltMapper.queryTraceAsphalt(traceasphalt);
	}
	@Override
	public TraceAsphaltModel updateTraceAsphalt(TraceAsphaltModel traceasphalt){
		traceasphaltMapper.updateTraceAsphalt(traceasphalt);
		return null;
	}
	
	@Override
	public Integer deleteTraceAsphalt(TraceAsphaltModel traceasphalt){
		return traceasphaltMapper.deleteTraceAsphalt(traceasphalt);
	}
	
	@Autowired
	private IntfaceMapper intfaceMapper;
	
	@Override
	public Result viewQuality(String id) {
		Result rs = new Result();
		Map<String,String> map = new HashMap<String,String>();
		try{
			JSONObject json = new JSONObject();
			TraceAsphaltModel traceAsphalt = new TraceAsphaltModel();
			traceAsphalt.setId(id);
			traceAsphalt = traceasphaltMapper.queryTraceAsphalt(traceAsphalt);
			json.put("traceAsphalt", traceAsphalt);
			map.put("sectionId", traceAsphalt.getSectionId());
			List<HashMap<String,String>> consList = intfaceMapper.querySysConstructionVehicleByAreaId(map);
			json.put("consList", consList);
			rs.setCode(Result.CODE_OK);
			rs.setData(json);
		}catch(Exception ex){
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg(ResMsg.EXECERR);
		}
		return rs;
	}

}